package cn.lavender.crypto.symmetry;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import org.apache.tomcat.util.codec.binary.Base64;

/**
 * <p>
 * 对称算法：AES
 * </p>
 *
 * @author: zhu.chen
 * @date: 2021/3/20
 * @version: v1.0.0
 */
public class AesCrypto {

    private static final AES AES = SecureUtil.aes();

    /**
     * 加密
     *
     * @param data
     * @return
     */
    public static String encrypt(String data) {
        return Base64.encodeBase64String(AES.encrypt(data));
    }

    /**
     * 解密
     *
     * @param cipher
     * @return
     */
    public static String decrypt(String cipher) {
        return new String(AES.decrypt(Base64.decodeBase64(cipher)));
    }

    public static void main(String[] args) {
        String cipher = AesCrypto.encrypt("小明");
        System.out.println(cipher);
        System.out.println(AesCrypto.decrypt(cipher));
    }

}
